package com.supinfo.sun.sungamers.gui;

import java.util.List;

import javax.swing.table.DefaultTableModel;

import com.supinfo.sun.sungamers.dao.impl.PersonFile;
import com.supinfo.sun.sungamers.person.Person;

/**
 * @author Liu, Bing(Locke)
 * @since 2011-6-5
 * @version 0.3
 */
public class PersonTableModel extends DefaultTableModel {

	private PersonFile personFile;
	
	@Override
	public int getColumnCount() {
		return 4;
	}
	
	@Override
	public int getRowCount() {
		personFile = new PersonFile();
		return personFile.getPersons().size();
	}



	@Override
	public boolean isCellEditable(int row, int column) {
		if(row == 0) {
			return false;
		}
		return true;
	}

	@Override
	public String getColumnName(int column) {
		if(column == 0)
			return "ID";
		else if(column == 1)
			return "Firstname";
		else if(column == 2)
			return "Lastname";
		else if(column == 3)
			return "Sex";
		return null;
	}

	@Override
	public Object getValueAt(int row, int column) {
		personFile = new PersonFile();
		Person p = personFile.getPerson(row + 1);
		if(column == 0)
			return p.getId();
		else if(column == 1)
			return p.getFirstName();
		else if(column == 2)
			return p.getLastName();
		else if(column == 3)
			return p.getSex();
		return p;
	}
}
